using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Parseq.Core
{
    public struct Result
    {
        public readonly object Inner; // this is what's returned. 
        public readonly Location Position; 
        public Result(object inner, Location pos)
        {
            this.Inner = inner;
            this.Position = pos; 
        }

        public static object[] ExtractInners(Result[] results)
        {
            object[] inners = new object[results.Length];
            for (int j = 0; j < results.Length; ++j)
            {
                inners[j] = results[j].Inner;
            }
            return inners;
        }

        public static bool Failed(Result r)
        {
            return r.Inner == null;
        }

        public static bool Succeeded(Result r)
        {
            return !Failed(r);
        }

        public static Result MakeFail(IReader reader, Location pos)
        {
            return new Result(null, pos);
        }
    }
}
